menu = {}

m = gui()

function menu.load()
	logo = lg.newImage("logo.png")

	local gamestart = gui:button('start game',{
		x = lg.getWidth()/2 - 64, y = lg.getHeight()/2,
		w = 128, h = gui.style.unit
	})
	gamestart.click = function(this,x,y)
		currState = 2
		game.load()
	end

	local inputNickname = gui:input('nickname',{
		x = lg.getWidth()/2 - 64, y = lg.getHeight()/2 + gui.style.unit + 5,
		w = 62, h = gui.style.unit
	})
	inputNickname.keyrepeat = true
	inputNickname.done = function(this)
		nickname = this.value
	end
	local setNickname = gui:button("set nick",{
		x = lg.getWidth()/2 + 2, y = lg.getHeight()/2 + gui.style.unit + 5,
		w = 62, h = gui.style.unit
			})
	setNickname.click = function(this,x,y) inputNickname:done() end

	local inputServer = gui:input('Server',{
		x = lg.getWidth()/2 - 64, y = lg.getHeight()/2 + gui.style.unit * 2 + 5 * 2,
		w = 62, h = gui.style.unit
	})
	inputServer.keyrepeat = true
	inputServer.done = function(this)
		server = this.value
	end
	local setServer = gui:button("set server",{
		x = lg.getWidth()/2 + 2, y = lg.getHeight()/2 + gui.style.unit * 2 + 5 *2 ,
		w = 62, h = gui.style.unit
			})
	setServer.click = function(this,x,y) inputServer:done() end

	local inputPort = gui:input('Port',{
		x = lg.getWidth()/2 - 64, y = lg.getHeight()/2 + gui.style.unit * 3 + 5 * 3,
		w = 62, h = gui.style.unit
	})
	inputPort.keyrepeat = true
	inputPort.done = function(this)
		port = this.value
		print(port)
	end

	local setPort = gui:button("set port",{
		x = lg.getWidth()/2 + 2, y = lg.getHeight()/2 + gui.style.unit * 3 + 5 *3 ,
		w = 62, h = gui.style.unit
			})
	setPort.click = function(this,x,y) inputPort:done() end

	local site = gui:button('my website',{
		x = lg.getWidth() - 130, y = lg.getHeight() - 75,
		w = 128, h = gui.style.unit
	})
	site.click = function(this,x,y)
		love.system.openURL("https://uldo.space/")
	end
	local itch = gui:button('my itch.io',{
		x = lg.getWidth() - 130, y = lg.getHeight() - 50,
		w = 128, h = gui.style.unit
	})
	itch.click = function(this,x,y)
		love.system.openURL("https://ulduh.itch.io/")
	end
end

function menu.update(dt)
	gui:update(dt)
end

function menu.keyreleased(k)
	if gui.focus then 
		gui:keypress(k)
	end
end

function menu.draw()
  lg.setBackgroundColor(1,1,1)
  lg.setColor(1,1,1)
	gui:draw()
  lg.setColor(0,0,0)
	lg.print("nickname : "..nickname,10,10)
	lg.print("server : "..server,10,20)
	lg.print("port : "..port,10,30)
  lg.setColor(1,1,1)
	lg.draw(logo,lg.getWidth()/2 - logo:getWidth()/2,lg:getHeight()/2 - 200)
end

function menu.quit()
end

function love.textinput(t)
	if gui.focus then
		gui:textinput(t)
	end
end

return menu
